<template>
  <d2-container>
    <div class="row-ac pb-2">
      <div><el-button type="warning" @click="addCountry" icon="el-icon-plus">添加广告</el-button></div>
    </div>
    <div class="flex-1 ml-2">
      <el-table :data="advertisingsList" border stripe>
        <el-table-column align="center" type="selection" width="40" />
        <el-table-column align="center" label="序号" type="index" width="40" />
        <el-table-column align="center" label="广告名称" prop="adv_name" width="70" />
        <el-table-column align="center" label="图片" prop="image" width="130">
          <template slot-scope="scope">
            <el-popover placement="right" trigger="hover">
              <el-image slot="reference" style="width: 40px; height: 40px" :src="scope.row.image" fit="cover" />
              <el-image style="width: 220px; height: 220px" :src="scope.row.image" fit="contain" />
            </el-popover>
          </template>
        </el-table-column>
        <el-table-column align="center" label="广告分类" prop="category_name" width="70" />
        <el-table-column align="center" label="广告归属" prop="belong" width="70">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.belong == 1" type="success">会员中心</el-tag>
            <el-tag v-if="scope.row.belong == 2" type="success">购物车</el-tag>
            <el-tag v-if="scope.row.belong == 3" type="success">小说首页</el-tag>
            <el-tag v-if="scope.row.belong == 4" type="success">小说列表页</el-tag>
            <el-tag v-if="scope.row.belong == 5" type="success">小说详情页</el-tag>
            <el-tag v-if="scope.row.belong == 6" type="success">解题首页</el-tag>
            <el-tag v-if="scope.row.belong == 7" type="success">解题列表页</el-tag>
            <el-tag v-if="scope.row.belong == 8" type="success">解题详情页</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="广告位置" prop="position" width="70">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.position == 1" type="primary">位置一</el-tag>
            <el-tag v-if="scope.row.position == 2" type="primary">位置二</el-tag>
            <el-tag v-if="scope.row.position == 3" type="primary">位置三</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="应用程序" prop="application" width="70">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.application == 1" type="warning">移动端</el-tag>
            <el-tag v-if="scope.row.application == 2" type="warning">网页端</el-tag>
          </template>
        </el-table-column>
        <el-table-column align="center" label="路由地址" prop="route" width="145" />
        <el-table-column align="center" label="广告语" prop="describe" width="160" />
        <el-table-column align="center" label="操作" width="180">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.row.id)">修改</el-button>
            <el-button size="mini" type="danger" @click="openDelete(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </d2-container>
</template>

<script>
  import {
    classificationListUrl,
    advertisingListUrl,
    advertisingDeleteUrl,
  } from "@/utils/picture"
  export default {
    name: 'brand',
    data() {
      return {
        queryInfo: {
          page: 1,
          pageSize: 10
        },
        advertisingsList: [],
      }
    },
    created() {
      this.initData()
    },
    methods: {
      initData() {
        this.getAdvertisingsList()
      },
      getAdvertisingsList() {
        this.$get(advertisingListUrl, this.queryInfo).then(res => {
          this.advertisingsList = res.data.data.list
          this.advertisingsTotal = res.data.data.total
        })
      },
      
      addCountry() {
        this.$router.push('/advertising/addAdvertising');
      },
      handleEdit(adverId) {
        this.$router.push({
          path: '/advertising/addAdvertising',
          query: {
            adverId: adverId // 添加第二个参数
          }
        });
      },
      openDelete(adverId) {
        this.$confirm('此操作将删除该广告?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.adverDelete(adverId)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消修改'
          });
        });
      },
      adverDelete(adverId) {
        this.$del(advertisingDeleteUrl + adverId + '/').then(res=>{
          console.log(res);
          this.getAdvertisingsList()
        })
      }
    }
  }
</script>
<style lang="scss">
</style>
